package ilarele.planner.Constants;

import java.util.Calendar;

public class ConstantValues
{
	public final static int[] MONTH_30 = {3, 5, 8, 10};
	public final static int[] MONTH_31 = {0, 2, 4, 6, 7, 9, 11};
	public final static int MONTH_VARIABLE = 1;
	private static final long MILLSECS_PER_DAY = 86400000; // 1000 * 60 * 60 * 24
	
	
	// sizes
	public final static int DAY_WIDTH_DP = 70;
	public final static int DAY_HEIGHT_DP = 42;
	
	
	public static int getMonthDays(int m, int y)
	{
		if (has31days(m))
			return 31;
		if (has30days(m))
			return 30;
		if (has28days(m, y))
			return 28;
		return 29;
	}
	public static boolean has30days(int crt)
	{
		for (int el : MONTH_30)
		{
			if (el == crt)
				return true;
		}
		return false;
	}
	
	public static boolean has31days(int crt)
	{
		for (int el : MONTH_31)
		{
			if (el == crt)
				return true;
		}
		return false;
	}
	
	public static boolean has28days(int m, int y)
	{
		if (m == MONTH_VARIABLE)
		{
			if (y % 4 != 0)
				return true;
		}
		return false;
	}
	
	public static void copyCalendar(Calendar old_c, Calendar new_c) {
		int year = old_c.get(Calendar.YEAR);
		int month = old_c.get(Calendar.MONTH);
		int day = old_c.get(Calendar.DAY_OF_MONTH);
		new_c.set(year, month, day, 0, 0 , 0);
		new_c.set(Calendar.MILLISECOND, 0);
	}
	
	public static Calendar copyCalendar(Calendar old_c) {
		Calendar new_c = Calendar.getInstance();
		int year = old_c.get(Calendar.YEAR);
		int month = old_c.get(Calendar.MONTH);
		int day = old_c.get(Calendar.DAY_OF_MONTH);
		new_c.set(year, month, day, 0, 0, 0);
		new_c.set(Calendar.MILLISECOND, 0);
		return new_c;
	}
	
	public static int getDiff(Calendar finish, Calendar start)
	{
		return (int) ((finish.getTimeInMillis() - start.getTimeInMillis()) / MILLSECS_PER_DAY);
	}
	public static Calendar getTodayCalendar()
	{
		Calendar c = Calendar.getInstance();
		c.set(Calendar.HOUR, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		return c;
	}
}
